<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/common/header.jsp"%> 
 
<div style="margin:20px 0;"></div>
<div class="easyui-panel" >
	<div style="padding:10px 60px 20px 60px">
    <form id="infchngrpForm"  name="infchngrpForm" method="post" >
    	<input type="hidden" id="chn_grp_uuid" name="chn_grp_uuid" value="${infChnGrp.chn_grp_uuid}"/>
    	<input type="hidden" id="channel_grp_uuid" name="channel_grp_uuid" value="${infChnGrp.channel_grp_uuid}"/>
    	<input type="hidden" id="channel_uuid" name="channel_uuid" value="${infChnGrp.channel_uuid}"/>
    	<table cellpadding="5" style="width:100%">
    		<tr>
    			<td>通道组别:</td>
    			<td><input class="easyui-textbox" type="text" readonly="readonly" id="chngrpname" value="${infChnGrp.chngrpname}" data-options="required:true"/>
    			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" id="selelctChnGrp">选择</a></td>   		    			 			   		     			
		    </tr>
		    <tr>
    			<td>通道名称:</td>
    			<td><input class="easyui-textbox" type="text" readonly="readonly" id="chnname" value="${infChnGrp.chnname}" data-options="required:true"/>
    			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" id="selelctChn">选择</a></td>   		    			 			   		     			
		    </tr>
    		<tr>
    			<td>优先级:</td>
    			<td><input class="easyui-textbox" type="text" name="priority" data-options="required:true,validType:['checkpriority']" value="${infChnGrp.priority }"></input></td>    	     			
    		</tr>     		 		  		    		 
    	</table>
    
	    <div style="text-align:center;padding:5px">
	    	<a href="javascript:void(0)" class="easyui-linkbutton btn" iconCls="icon-save" id="saveBtn">保存</a>
	    	<a href="javascript:void(0)" class="easyui-linkbutton btn" iconCls="icon-back" onclick="back()">返回</a>
	    </div>
    </form>
    </div>
</div>

<div id="dialogChnGrp">
	<div style="padding:3px" class="easyui-panel datagrid-toolbar">
		<div>
			<span>通道组别编号:</span>
			<input id="channel_grp" type="text" name="channel_grp"  class="easyui-textbox"  >					
		 	<a href="#" class="easyui-linkbutton btn"   onclick="chnGrpSearch() ">查询</a>
		 	<a href="#" class="easyui-linkbutton btn" onclick="resetParam() ">重置</a>
		</div>	 
	</div>
    <table id="tableChnGrp">			 
	</table>
	
</div>
<div id="dialogChn">
	<div style="padding:3px" class="easyui-panel datagrid-toolbar">
		<div>
			<span>通道编号:</span>
			<input id="channel_no" type="text" name="channel_no"  class="easyui-textbox"  >					
		 	<a href="#" class="easyui-linkbutton btn"   onclick="chnSearch() ">查询</a>
		 	<a href="#" class="easyui-linkbutton btn" onclick="resetParam() ">重置</a>
		</div>	 
	</div>
    <table id="tableChn">			 
	</table>
	
</div>

<script>
$(document).ready(function() {
	$("#dialogChnGrp").attr("style", "display: none;");
	$("#dialogChn").attr("style", "display: none;");
	$.extend($.fn.textbox.defaults.rules, {
		checkpriority: {     
            validator: function(value){               
                 var reg = new RegExp("^[0-9]{0,2}$"); 
                 return reg.test(value);  
            },     
            message: '优先级需为0-2位的数字'     
        }      
	});
	var chnGrpGrid;
	$("#selelctChnGrp").click(function(){
		chnGrpGrid = $("#tableChnGrp").jpgrid({
			url: "../channelgrp/getChannelGrpListJson.do",
			columns: [
						{title: "通道组别编号", field: "CHANNEL_GRP",width:100},
						{title: "通道组别描述", field: "DESCPT"}												
					]
		});
		openModal("#dialogChnGrp", {width:800, height:400,title:"选择通道组别"}, saveChnGrp);
		
	})
	var chnGrid;
	$("#selelctChn").click(function(){
		chnGrid = $("#tableChn").jpgrid({
			url: "../channelinf/getChannelInfListJson.do",
			columns: [
						{title: "通道编号", field: "CHANNEL_NO",width:100},
						{title: "通道名称", field: "CHN_NM"},
						{title: "通道类型", field: "CHN_TP",width:100},
						{title: "通道对应表", field: "CHN_PRMTB"},
						{title: "交易频率", field: "TRANS_INTERVAL",width:80}
					]
		});
		openModal("#dialogChn", {width:800, height:400,title:"选择通道"}, saveChn);
	})
	
	$("#saveBtn").click(function(){	
		if($("#infchngrpForm").form("validate")){			
			var options ={   
		            url:'<c:url value="/infchngrp/checkChnGrp.do"/>',   
		            type:'post',                    
		            success:function(data){		            	  
						  if("success"==data){					  
							  //表单提交的方法、比如ajax提交
					    	  $("#infchngrpForm").attr("action","../infchngrp/saveInfChnGrp.do?");
					    	  document.getElementById("infchngrpForm").submit();  						  
						  }else{
							  $.jpmessage.info('同一通道组别下通道名称不能重复!');
						  }
		            }   
		         };
			$("#infchngrpForm").ajaxSubmit(options); 
		}
	});
	$("body").keydown(function() {
        if (event.keyCode == "13") {//keyCode=13是回车键
            $('#saveBtn').click();
        }
    });
})

function chnGrpSearch() {	 
	chnGrpGrid.load({
		channel_grp: $('#channel_grp').val()						
	});
}
function chnSearch() {	 
	chnGrid.load({
		channel_no: $('#channel_no').val()							
	});
}
function resetParam(){		
	$("#channel_grp").textbox("setValue", "");	
	$("#channel_no").textbox("setValue", "");
}

function saveChnGrp(){
	return commonsave("tableChnGrp","channel_grp_uuid","chngrpname","dialogChnGrp");	
}
function saveChn(){
	return commonsave("tableChn","channel_uuid","chnname","dialogChn");	
}
function commonsave(tableid,id,name,dialog){	
	var rows = $('#'+tableid).datagrid('getSelections');	
	if(rows.length==0){					
		$.jpmessage.warning('请至少选择一条记录!');		
 		return false;
	}
	if(rows.length>1){			
		$.jpmessage.warning('只能选择一条记录!');
		return false;
	}
	
	$("#"+id).val(rows[0].UUID);
	if("chngrpname"==name){		
		$("#chngrpname").textbox("setValue", rows[0].CHANNEL_GRP+"-"+rows[0].DESCPT);
	}
	if("chnname"==name){				
		$("#chnname").textbox("setValue", rows[0].CHANNEL_NO+"-"+rows[0].CHN_NM);
	}	
	return;
}
</script>